﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading;
using System.Xml.Serialization;


namespace SetNet
{
    
    public class Serialization
    {

        public static byte[] Serializate(EventData eData)
        {

            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            
            formatter.Serialize(stream, eData);
            byte[] msg = stream.ToArray();
            return msg;
        }
        public static EventData Deserializate(byte[] eData)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            stream.Write(eData, 0, eData.Length);
            stream.Position = 0;
            try
            {

                return (EventData)formatter.Deserialize(stream);

            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return null;
            }
        }
    }
}
